<?php
/**
 * Created by 天沁信息科技.
 * User: 小涛.
 * Date: 2018/12/29
 * Time: 10:27
 */

namespace app\admin\model;


use think\Model;
use think\Request;

/**
 * Class Goods 商品信息
 * @package app\admin\model
 */
class Goods extends Model
{
    //商品logo与图片的对应关系
    public function UploadLogo(){
        return $this -> belongsTo("Upload","logo","id");
    }

    //商品父分类与商品分类的对应关系
    public function TypeById(){
        return $this -> belongsTo("GoodsType","type_id","id");
    }

    //商品分类与商品分类的对应关系
    public function TypeByIds(){
        return $this -> belongsTo("GoodsType","type_ids","id");
    }

    //列表
    public static function listGoods($is_shelf = 0,$listRow = 0){
        $list = self::with("UploadLogo,TypeById,TypeByIds")
            -> where(["is_shelf" => $is_shelf])
            -> order("sort asc");
        if($listRow == 0){
            return $list -> select();
        }
        return $list -> paginate($listRow,false,[
            "query" => Request::instance() -> param()
        ]);
    }
}